# Contributor: Alexander Edland <alpine@ocv.me>
# Contributor: knuxify <knuxify@gmail.com>
# Maintainer:
pkgname=mgba
pkgver=0.9.3
pkgrel=1
pkgdesc="Game Boy Advance Emulator"
url="https://mgba.io"
arch="all !s390x" # broken on big-endian
arch="$arch !armhf" # Missing qt5-qtmultimedia-dev
license="MPL-2.0"
makedepends="cmake qt5-qtmultimedia-dev qt5-qtbase-dev qt5-qttools-dev
	sdl2-dev libzip-dev zlib-dev libpng-dev ffmpeg-dev imagemagick-dev
	libepoxy-dev cmocka-dev libedit-dev py3-virtualenv python3-dev
	libzip-tools elfutils-dev samurai
	"
checkdepends="py3-cffi py3-cached-property"
subpackages="$pkgname-doc libmgba:_libmgba libmgba-dev $pkgname-qt:_qt"
source="mgba-$pkgver.tar.gz::https://github.com/mgba-emu/mgba/archive/$pkgver.tar.gz
	ffmpeg5.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -G Ninja -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_TEST:BOOL=ON \
		-DBUILD_SUITE:BOOL=ON \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# remove test leftovers
	rm "$pkgdir"/usr/bin/mgba-fuzz
	rm "$pkgdir"/usr/bin/tbl-fuzz
}

_qt() {
	pkgdesc="Qt5 frontend for the mGBA emulator"

	mkdir -p "$subpkgdir"/usr/share/applications
	amove usr/bin/mgba-qt
	amove usr/share/applications/mgba-qt.desktop
}

_libmgba() {
	pkgdesc="Shared library of mGBA"

	amove usr/lib
}

sha512sums="
da65b3c7ec32d732163f129c4fd38949ae2da2980beb3257bf6def5e35534a27b6d30309bb3c9a8d651642f99e1a45db7a8577c8dbf5472153d4551167471b3a  mgba-0.9.3.tar.gz
3f714c1c950636a5938d4226b8120bd566ec65a922a9ea43b01913e266b0b81e2334fef37b73fa3e1fd0cd2ffb619f14283ce5ded328e99b28af34f40c77b2c2  ffmpeg5.patch
"
